package com.faxsun.core.tool;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import com.faxsun.common.currency.domain.FSCurrencyEnum;
import com.faxsun.core.catalog.domain.CountryEnum;

/**
 * 静态资源加载，用于加载一段时间内不发生变化的资源，例如：城市、汇率种类
 * @author zhaoteng.song@faxsun.com
 *
 */
public class ResourceLoader implements BeanPostProcessor {

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		return bean;
	}

	/**
	 * class初始化后执行加载，调用对应实例的init方法
	 */
	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {
		if (bean instanceof CountryEnum)
		{
			((CountryEnum) bean).init();
		}
		else if(bean instanceof FSCurrencyEnum){
			((FSCurrencyEnum) bean).init();
		}
		return bean;
	}

}
